﻿using System;
using System.Collections.Generic;
using System.Linq;
using Assets.Scripts.GtsScripts;
using UnityEngine;

namespace AI
{
	// Token: 0x020001F4 RID: 500
	public class GTSDecisionMaker : DecisionMaker
	{
		// Token: 0x06000AB2 RID: 2738 RVA: 0x0005B8B2 File Offset: 0x00059AB2
		public GTSDecisionMaker(Humanoid entity) : base(entity)
		{
		}

		// Token: 0x06000AB3 RID: 2739 RVA: 0x0005B8BB File Offset: 0x00059ABB
		public override void Execute()
		{
			if (this.ai.IsIdle())
			{
				this.MakeDecision();
			}
		}

		// Token: 0x06000AB4 RID: 2740 RVA: 0x0005B8D4 File Offset: 0x00059AD4
		private void MakeDecision()
		{
			List<TargetType> agentDefs = BehaviorLists.Instance.FindDefs(this.entity, null);
			List<TargetType> list = new List<TargetType>();
			list.Add(TargetType.Oneself);
			list.Add(TargetType.None);
			if (GameController.playerInstance.IsTargettable())
			{
				list.Add(TargetType.Player);
			}
			Micro randomMicro = MicroManager.GetRandomMicro(this.entity);
			if (randomMicro)
			{
				list.Add(TargetType.Micro);
			}
			Giantess randomGiantess = this.GetRandomGiantess();
			if (randomGiantess)
			{
				list.Add(TargetType.Giantess);
			}
			List<IBehavior> list2 = BehaviorLists.Instance.FindBehaviors(agentDefs, list);
			list2 = list2.FindAll((IBehavior beh) => beh.IsAI());
			if (list2.Count == 0)
			{
				return;
			}
			IBehavior behavior = base.ChooseBehavior(list2);
			if (behavior == null)
			{
				return;
			}
			if (GlobalPreferences.ScriptAuxLogging.value)
			{
				Debug.Log("Giantess Behavior: " + behavior.GetName());
			}
			List<EntityBase> list3 = new List<EntityBase>();
			List<TargetType> include = behavior.GetTargetDef().include;
			foreach (TargetType targetType in include)
			{
				if (targetType == TargetType.Micro && randomMicro)
				{
					list3.Add(randomMicro);
				}
				else if (targetType == TargetType.Player)
				{
					list3.Add(GameController.playerInstance);
				}
				else if (targetType == TargetType.Giantess && randomGiantess)
				{
					list3.Add(randomGiantess);
				}
				else if (targetType == TargetType.Humanoid)
				{
					if (randomMicro)
					{
						list3.Add(randomMicro);
					}
					if (randomGiantess)
					{
						list3.Add(randomGiantess);
					}
				}
			}
			EntityBase target = null;
			if (list3.Count > 0)
			{
				target = list3[UnityEngine.Random.Range(0, list3.Count)];
			}
			this.ai.ScheduleCommand(behavior, target, base.getRandomPoint());
		}

		// Token: 0x06000AB5 RID: 2741 RVA: 0x0005BAEC File Offset: 0x00059CEC
		private Giantess GetRandomGiantess()
		{
			List<Giantess> list = ObjectManager.Instance.giantessList.Values.ToList<Giantess>();
			int count = list.Count;
			if (count > 0)
			{
				return list[UnityEngine.Random.Range(0, count)];
			}
			return null;
		}
	}
}
